﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using System.Data.SqlClient;


namespace QUAN_LY_MUON_TRA_SACH
{
    public partial class frmMain : RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
            InitSkinGallery();

        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }
        SqlCommand lenh1;
        private void frmMain_Load(object sender, EventArgs e)
        {   
            //     
            barbtndangxuat.Enabled = false;
            barbtndoipass.Enabled = false;
            barbtnsaoluu.Enabled = false;
            barbtnphuchoi.Enabled = false;
            barbtndsdocgia.Enabled = false;
            barthemdocgia.Enabled = false;
            barsuadocgia.Enabled = false;
            barbtnhuydocgia.Enabled = false;
            barbtnloaidg.Enabled = false;
            barbtntacgia.Enabled = false;
            
            barbtnmuon.Enabled = false;
            barsachdangmuon.Enabled = false;
            barbtntra.Enabled = false;
            barbtnphat.Enabled = false;
            barbtndsphat.Enabled = false;
            
            barbtntim.Enabled = false;
            barsachmuonnhieu.Enabled = false;
            barsachkomuon.Enabled = false;
            bardsquahan.Enabled = false;
            bardsbiphat.Enabled = false;
            barmuontheotloai.Enabled = false;
            barmuontungnam.Enabled = false;
            bardsmuontheoquyen.Enabled = false;
            //
            bardxuat.Enabled = false;
            barmuon.Enabled = false;
            bartra.Enabled = false;
            barsaoluu.Enabled = false;
            barphuchoi.Enabled = false;
            barthemdg.Enabled = false;
            barhuydg.Enabled = false;
            barbaocao.Enabled = false;
            barphat.Enabled = false;
            bartracuc.Enabled = false;
            barmuonnhieu.Enabled = false;
            barkomuon.Enabled = false;
            barquahan.Enabled = false;
            bardsphat.Enabled = false;
            barlmnam.Enabled = false;
            barlmquyen.Enabled = false;
            barlmtl.Enabled = false;
            
            //cap nhat nhung the doc gia da het han
            try
            {
                lenh1 = new SqlCommand("update the_doc_gia set ttrangthe=N'đã hết hạn' where ngayhethan<getdate()", Connection.sqlConnection);
                SqlDataReader S=lenh1.ExecuteReader();
                S.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                lenh1.Dispose();
            }
            
        }

        private void barButtonItem32_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "BÁO CÁO LƯỢT MƯỢN \nTHEO TỪNG THỂ LOẠI";
            grbtheongay.Enabled = true;
            grbtheonam.Enabled = false;
        }

        private void xtraTabPage1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void barButtonItem7_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (Connection.Connect()) Connection.Close();
            frmdangnhap Frmdangnhap = new frmdangnhap();
            Frmdangnhap.Show();
        }

        private void iExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            Application.Exit();
        }

        private void navBarControl_Click(object sender, EventArgs e)
        {
            
        }

        private void barbtndangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (Connection.Connect()) Connection.Close();
            frmdangnhap Frmdangnhap = new frmdangnhap();
            Frmdangnhap.ShowDialog();
        }

        private void barbtndangxuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabControl1.Enabled = false;
            xtraTabPagekqtimkiem.PageVisible = false;
            
            
            barbtndangxuat.Enabled = false;
            barbtndoipass.Enabled = false;
            barbtnsaoluu.Enabled = false;
            barbtnphuchoi.Enabled = false;
            barbtndsdocgia.Enabled = false;
            barthemdocgia.Enabled = false;
            barsuadocgia.Enabled = false;
            barbtnhuydocgia.Enabled = false;
            barbtnloaidg.Enabled = false;
            barbtntacgia.Enabled = false;
            
            barbtnmuon.Enabled = false;
            barsachdangmuon.Enabled = false;
            barbtntra.Enabled = false;
            barbtnphat.Enabled = false;
            barbtndsphat.Enabled = false;
            
            barbtntim.Enabled = false;
            barsachmuonnhieu.Enabled = false;
            barsachkomuon.Enabled = false;
            bardsquahan.Enabled = false;
            bardsbiphat.Enabled = false;
            barmuontheotloai.Enabled = false;
            barmuontungnam.Enabled = false;
            bardsmuontheoquyen.Enabled = false;
            //
            bardnhap.Enabled = false;
            bardxuat.Enabled = false;
            barmuon.Enabled = false;
            bartra.Enabled = false;
            barsaoluu.Enabled = false;
            barphuchoi.Enabled = false;
            barthemdg.Enabled = false;
            barhuydg.Enabled = false;
            barbaocao.Enabled = false;
            barphat.Enabled = false;
            bartracuc.Enabled = false;
            barmuonnhieu.Enabled = false;
            barkomuon.Enabled = false;
            barquahan.Enabled = false;
            bardsphat.Enabled = false;
            barlmnam.Enabled = false;
            barlmquyen.Enabled = false;
            barlmtl.Enabled = false;
            //
            xtraTabPagedsdgia.PageVisible = false;
            xtraTabPagetacgia.PageVisible = false;
            
            //Connection.Close();
            //Connection.sqlConnection.Dispose();
            
            //
            FORM_MAIN.frmmain.barbtndangnhap.Enabled = true;
            FORM_MAIN.frmmain.bardnhap.Enabled = true;
            
            //
            FORM_MAIN.frmmain.barlogtime.Caption = "Thời Gian Đăng Xuất";
            FORM_MAIN.frmmain.bartime.Caption = DateTime.Now.ToString();
            FORM_MAIN.frmmain.siInfo.Enabled = false;
            FORM_MAIN.frmmain.barchucvu.Enabled = false;
            FORM_MAIN.frmmain.bartime.Enabled = false;
            FORM_MAIN.frmmain.barmsnv.Enabled = false;
            
            
        }

        private void frmMain_Activated(object sender, EventArgs e)
        {
            
        }

        private void ibxdnhap_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            if (Connection.Connect()) Connection.Close();
            frmdangnhap Frmdangnhap = new frmdangnhap();
            Frmdangnhap.Show();
        }

        private void ibxdxuat_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            xtraTabControl1.Visible = false;
            
            
            
            barbtndangxuat.Enabled = false;
            barbtndoipass.Enabled = false;
            barbtnsaoluu.Enabled = false;
            barbtnphuchoi.Enabled = false;
            barbtndsdocgia.Enabled = false;
            barthemdocgia.Enabled = false;
            barsuadocgia.Enabled = false;
            barbtnhuydocgia.Enabled = false;
            barbtnloaidg.Enabled = false;
            barbtntacgia.Enabled = false;
            
            barbtnmuon.Enabled = false;
            barsachdangmuon.Enabled = false;
            barbtntra.Enabled = false;
            barbtnphat.Enabled = false;
            barbtndsphat.Enabled = false;
            
            barbtntim.Enabled = false;
            barsachmuonnhieu.Enabled = false;
            barsachkomuon.Enabled = false;
            bardsquahan.Enabled = false;
            bardsbiphat.Enabled = false;
            barmuontheotloai.Enabled = false;
            barmuontungnam.Enabled = false;
            bardsmuontheoquyen.Enabled = false;
            //
            bardnhap.Enabled = false;
            bardxuat.Enabled = false;
            barmuon.Enabled = false;
            bartra.Enabled = false;
            barsaoluu.Enabled = false;
            barphuchoi.Enabled = false;
            barthemdg.Enabled = false;
            barhuydg.Enabled = false;
            barbaocao.Enabled = false;
            barphat.Enabled = false;
            bartracuc.Enabled = false;
            barmuonnhieu.Enabled = false;
            barkomuon.Enabled = false;
            barquahan.Enabled = false;
            bardsphat.Enabled = false;
            barlmnam.Enabled = false;
            barlmquyen.Enabled = false;
            barlmtl.Enabled = false;
            //
            
            
            
            
            
            
            

            xtraTabPagedsdgia.PageVisible = false;
            Connection.Close();
            Connection.sqlConnection.Dispose();
            //
            FORM_MAIN.frmmain.barbtndangnhap.Enabled = true;
            FORM_MAIN.frmmain.bardnhap.Enabled = true;
            
            //
            FORM_MAIN.frmmain.barlogtime.Caption = "Thời Gian Đăng Xuất";
            FORM_MAIN.frmmain.bartime.Caption = DateTime.Now.ToString();
            FORM_MAIN.frmmain.siInfo.Enabled = false;
            FORM_MAIN.frmmain.barchucvu.Enabled = false;
            FORM_MAIN.frmmain.bartime.Enabled = false;
            
        }

        private void bardxuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabControl1.Enabled = false;
            xtraTabPagekqtimkiem.PageVisible = false;
            
            
            barbtndangxuat.Enabled = false;
            barbtndoipass.Enabled = false;
            barbtnsaoluu.Enabled = false;
            barbtnphuchoi.Enabled = false;
            barbtndsdocgia.Enabled = false;
            barthemdocgia.Enabled = false;
            barsuadocgia.Enabled = false;
            barbtnhuydocgia.Enabled = false;
            barbtnloaidg.Enabled = false;
            barbtntacgia.Enabled = false;
            
            barbtnmuon.Enabled = false;
            barsachdangmuon.Enabled = false;
            barbtntra.Enabled = false;
            barbtnphat.Enabled = false;
            barbtndsphat.Enabled = false;
            
            barbtntim.Enabled = false;
            barsachmuonnhieu.Enabled = false;
            barsachkomuon.Enabled = false;
            bardsquahan.Enabled = false;
            bardsbiphat.Enabled = false;
            barmuontheotloai.Enabled = false;
            barmuontungnam.Enabled = false;
            bardsmuontheoquyen.Enabled = false;
            //
            bardnhap.Enabled = false;
            bardxuat.Enabled = false;
            barmuon.Enabled = false;
            bartra.Enabled = false;
            barsaoluu.Enabled = false;
            barphuchoi.Enabled = false;
            barthemdg.Enabled = false;
            barhuydg.Enabled = false;
            barbaocao.Enabled = false;
            barphat.Enabled = false;
            bartracuc.Enabled = false;
            barmuonnhieu.Enabled = false;
            barkomuon.Enabled = false;
            barquahan.Enabled = false;
            bardsphat.Enabled = false;
            barlmnam.Enabled = false;
            barlmquyen.Enabled = false;
            barlmtl.Enabled = false;
            //
            
            
            
            
            
            
           

            xtraTabPagedsdgia.PageVisible = false;
            //Connection.Close();
            //Connection.sqlConnection.Dispose();
            //
            FORM_MAIN.frmmain.barbtndangnhap.Enabled = true;
            FORM_MAIN.frmmain.bardnhap.Enabled = true;
            
            //
            FORM_MAIN.frmmain.barlogtime.Caption = "Thời Gian Đăng Xuất";
            FORM_MAIN.frmmain.bartime.Caption = DateTime.Now.ToString();
            FORM_MAIN.frmmain.siInfo.Enabled = false;
            FORM_MAIN.frmmain.barchucvu.Enabled = false;
            FORM_MAIN.frmmain.bartime.Enabled = false;
            
        }

        private void rgbiSkins_ItemClick(object sender, ItemClickEventArgs e)
        {
            skinsRibbonPageGroup.Visible = false;
        }

        private void barbtndoipass_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmdoipass Frmdoipass = new frmdoipass();
            Frmdoipass.ShowDialog();
        }

        private void barbtndsdocgia_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagedsdgia.PageVisible = true;
            xtraTabControl2.SelectedTabPage = xtraTabPagedsdgia;
        }

        private void barthemdocgia_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmthemdocgia Frmthemdocgia = new frmthemdocgia();
            Frmthemdocgia.ShowDialog();
        }

        private void barthemdg_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmthemdocgia Frmthemdocgia = new frmthemdocgia();
            Frmthemdocgia.ShowDialog();
        }

        private void ibxthemdg_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            frmthemdocgia Frmthemdocgia = new frmthemdocgia();
            Frmthemdocgia.Show();
        }

        private void barbtnhuydocgia_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmhuydocgia Frmhuydocgia = new frmhuydocgia();
            Frmhuydocgia.ShowDialog();
        }

        private void ibxhuydg_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            frmhuydocgia Frmhuydocgia = new frmhuydocgia();
            Frmhuydocgia.Show();
        }

        private void barhuydg_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmhuydocgia Frmhuydocgia = new frmhuydocgia();
            Frmhuydocgia.ShowDialog();
        }

        private void btnthem_Click(object sender, EventArgs e)
        {
            frmthemdocgia Frmthemdocgia = new frmthemdocgia();
            Frmthemdocgia.ShowDialog();
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            int dem = 0;
            int ktra = 0;
            try
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        ktra++;
                    }
                }
                if (ktra == 0)
                    MessageBox.Show("Bạn chưa chọn nhà xuất bản để xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (MessageBox.Show("Bạn thật sự muốn xóa!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells[0].Value))
                        {
                            string idToDelete = row.Cells[1].Value.ToString();
                            SqlCommand lenh = new SqlCommand("delete from the_doc_gia where mathe='" + idToDelete + "'", Connection.sqlConnection);
                            int n = lenh.ExecuteNonQuery();
                            dem++;
                        }
                    }
                    if (dem > 0)
                        MessageBox.Show("Đọc giả đã được xóa!", "Cập nhật thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }                
                btndanhsach_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        internal void btndanhsach_Click(object sender, EventArgs e)
        {
            dataTable.Clear();
            chkmathe.CheckState = CheckState.Unchecked;
            chkhoten.CheckState = CheckState.Unchecked;

            chkcmnd.CheckState = CheckState.Unchecked;

            chkdiachi.CheckState = CheckState.Unchecked;

            chkdienthoai.CheckState = CheckState.Unchecked;

            chkemail.CheckState = CheckState.Unchecked;

            chkgioitinh.CheckState = CheckState.Unchecked;

            chkloaidg.CheckState = CheckState.Unchecked;

            chkngsinh.CheckState = CheckState.Unchecked;

            chkttrangthe.CheckState = CheckState.Unchecked;

            chkngaycap.CheckState = CheckState.Unchecked;

            chkngayhethan.CheckState = CheckState.Unchecked;
            
            
            try
            {

                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from the_doc_gia;", Connection.sqlConnection);
                sqlDataAdapter.Fill(dataTable);
                sqlDataAdapter.Dispose();
                this.dataGridView1.DataSource = dataTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void chkmathe_CheckedChanged(object sender, EventArgs e)
        {
            if (chkmathe.Checked)
            {
                cbomathe.Enabled = true;
                DataTable bang = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select mathe,hten_dg from the_doc_gia", Connection.sqlConnection);
                sqlDataAdapter.Fill(bang);
                cbomathe.DataSource = bang;
                cbomathe.ValueMember = "mathe";
                sqlDataAdapter.Dispose();
            }
            else
                cbomathe.Enabled = false;
        }

        private void chkhoten_CheckedChanged(object sender, EventArgs e)
        {
            if (chkhoten.Checked)
                txthoten.Enabled = true;
            else
                txthoten.Enabled = false;
        }

        private void chkngsinh_CheckedChanged(object sender, EventArgs e)
        {
            if (chkngsinh.Checked)
                cadngsinh.Enabled = true;
            else
                cadngsinh.Enabled = false;
        }

        private void chkcmnd_CheckedChanged(object sender, EventArgs e)
        {
            if (chkcmnd.Checked)
                txtcmnd.Enabled = true;
            else
                txtcmnd.Enabled = false;
        }

        private void chkgioitinh_CheckedChanged(object sender, EventArgs e)
        {
            if (chkgioitinh.Checked)
                cbogioitinh.Enabled = true;
            else
                cbogioitinh.Enabled = false;
        }

        private void chkloaidg_CheckedChanged(object sender, EventArgs e)
        {
            if (chkloaidg.Checked)
            {
                cboloaidg.Enabled = true;
                DataTable dbcbo_loaidg = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select ma_loai_dgia,dgiai from loai_doc_gia", Connection.sqlConnection);
                sqlDataAdapter.Fill(dbcbo_loaidg);
                cboloaidg.DataSource = dbcbo_loaidg;
                cboloaidg.ValueMember = "ma_loai_dgia";
            }
            else
                cboloaidg.Enabled = false;
        }

        private void chkdiachi_CheckedChanged(object sender, EventArgs e)
        {
            if (chkdiachi.Checked)
                txtdiachi.Enabled = true;
            else
                txtdiachi.Enabled = false;
        }

        private void chkdienthoai_CheckedChanged(object sender, EventArgs e)
        {
            if (chkdienthoai.Checked)
                txtdienthoai.Enabled = true;
            else
                txtdienthoai.Enabled = false;
        }

        private void chkemail_CheckedChanged(object sender, EventArgs e)
        {
            if (chkemail.Checked)
                txtemail.Enabled = true;
            else
                txtemail.Enabled = false;
        }

        private void chkttrangthe_CheckedChanged(object sender, EventArgs e)
        {
            if (chkttrangthe.Checked)
                cbottrangthe.Enabled = true;
            else
                cbottrangthe.Enabled = false;
        }

        private void chkngaycap_CheckedChanged(object sender, EventArgs e)
        {
            if (chkngaycap.Checked)
                cadngaycap.Enabled = true;
            else
                cadngaycap.Enabled = false;
        }

        private void chkngayhethan_CheckedChanged(object sender, EventArgs e)
        {
            if (chkngayhethan.Checked)
                cadnghhan.Enabled = true;
            else
                cadnghhan.Enabled = false;
        }

        private void btntimkiem_Click(object sender, EventArgs e)
        {
            try
            {
                bool stt = false;
                string mathe = "";
                if (chkmathe.Checked)
                {
                    mathe = "where mathe='" + cbomathe.Text + "'";
                    stt = true;
                }
                if (chkhoten.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where hten_dg=N'" + txthoten.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "hten_dg=N'" + txthoten.Text + "'";
                }
                if (chkngsinh.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where ngsinh_dg='" + cadngsinh.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "ngsinh_dg='" + cadngsinh.Text + "'";
                }
                if (chkcmnd.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where cmnd='" + txtcmnd.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "cmnd='" + txtcmnd.Text + "'";
                }
                if (chkgioitinh.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where gioitinh=N'" + cbogioitinh.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "gioitinh=N'" + cbogioitinh.Text + "'";
                }
                if (chkloaidg.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where ma_loai_dgia='" + cboloaidg.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "ma_loai_dgia='" + cboloaidg.Text + "'";
                }
                if (chkdiachi.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where diachi=N'" + txtdiachi.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "diachi=N'" + txtdiachi.Text + "'";
                }
                if (chkdienthoai.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where dienthoai='" + txtdienthoai.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "dienthoai='" + txtdienthoai.Text + "'";
                }
                if (chkemail.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where email='" + txtemail.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "email='" + txtemail.Text + "'";
                }
                if (chkttrangthe.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where ttrangthe=N'" + cbottrangthe.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "ttrangthe=N'" + cbottrangthe.Text + "'";
                }
                if (chkngaycap.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where ngaycap='" + cadngaycap.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "ngaycap='" + cadngaycap.Text + "'";
                }
                if (chkngayhethan.Checked)
                {
                    if (stt == false)
                    {
                        mathe += "where ngayhethan='" + cadnghhan.Text + "'";
                        stt = true;
                    }
                    else
                        mathe += " and " + "ngayhethan='" + cadnghhan.Text + "'";
                }
                DataTable dataTable = new DataTable();
                SqlDataAdapter sqlDataAdapter;
                if(mathe!="")
                    sqlDataAdapter = new SqlDataAdapter("select mathe,msnv,ma_loai_dgia,ma_ng,hten_dg,ngsinh_dg,gioitinh,cmnd,diachi,dienthoai,email,ngaycap,ngayhethan,ttrangthe from the_doc_gia " + mathe, Connection.sqlConnection);
                else
                    sqlDataAdapter = new SqlDataAdapter("select mathe,msnv,ma_loai_dgia,ma_ng,hten_dg,ngsinh_dg,gioitinh,cmnd,diachi,dienthoai,email,ngaycap,ngayhethan,ttrangthe from the_doc_gia where mathe=''", Connection.sqlConnection);
                sqlDataAdapter.Fill(dataTable);
                sqlDataAdapter.Dispose();
                this.dataGridView1.DataSource = dataTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        public void xtraTabControl2_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            //danh sach doc gia
            if(xtraTabControl2.SelectedTabPage==xtraTabPagedsdgia)
            {
                cbomathe.Enabled = false;
                txthoten.Enabled = false;
                txtcmnd.Enabled = false;
                txtdiachi.Enabled = false;
                txtdienthoai.Enabled = false;
                txtemail.Enabled = false;
                cbogioitinh.Enabled = false;
                cboloaidg.Enabled = false;
                cadngsinh.Enabled = false;
                cbottrangthe.Enabled = false;
                cadngaycap.Enabled = false;
                cadnghhan.Enabled = false;
                try
                {
                    dataTable.Clear();
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select mathe,msnv,ma_loai_dgia,ma_ng,hten_dg,ngsinh_dg,gioitinh,cmnd,diachi,dienthoai,email,ngaycap,ngayhethan,ttrangthe from the_doc_gia;", Connection.sqlConnection);
                    sqlDataAdapter.Fill(dataTable);
                    this.dataGridView1.DataSource = dataTable;
                    this.dataGridView1.ClearSelection();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi: " + ex.Message);
                }
            }
            else if(xtraTabControl2.SelectedTabPage==xtraTabPagetacgia)//danh sach tac gia
            {
                try
                {
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from tac_gia;", Connection.sqlConnection);
                    sqlDataAdapter.Fill(dataTabletacgia);
                    this.dataGridView2.DataSource = dataTabletacgia;
                    this.dataGridView2.ClearSelection();

                    //load du lieu len cbotacgia
                    DataTable table_tgia = new DataTable();
                    sqlDataAdapter = new SqlDataAdapter("select ma_tgia,ten_tgia,hocvi from tac_gia;", Connection.sqlConnection);
                    sqlDataAdapter.Fill(table_tgia);
                    cbotentg.DataSource = table_tgia;
                    cbotentg.ValueMember = "ma_tgia";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi: " + ex.Message);
                }
            }
            else if (xtraTabControl2.SelectedTabPage == xtraTabPagesachdangmuon)//danh sach sach dang muon
            {
                try
                {
                    dataTablesachdangmuon.Clear();
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select b.stt_phieu,b.mathe,hten_dg,d.isbn,stt_cuon,tuasach,lan_gia_han,ngay_het_han,ghi_chu from the_doc_gia a,phieu_muon b,gom_cuon c,dau_sach d where a.mathe=b.mathe and b.stt_phieu=c.stt_phieu and c.isbn=d.isbn and ngay_gio_tra is null order by b.stt_phieu asc", Connection.sqlConnection);
                    sqlDataAdapter.Fill(dataTablesachdangmuon);
                    this.dataGridView6.DataSource = dataTablesachdangmuon;
                    this.dataGridView6.ClearSelection();
                    sqlDataAdapter.Dispose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi: " + ex.Message);
                }
            }
            else if (xtraTabControl2.SelectedTabPage == xtraTabPagenxb)//danh sach nxb
            {
                try
                {
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from nha_xuat_ban;", Connection.sqlConnection);
                    sqlDataAdapter.Fill(dataTablenxb);
                    this.dataGridView5.DataSource = dataTablenxb;
                    this.dataGridView5.ClearSelection();

                    //load du lieu len cbomanxb
                    DataTable table_nxb = new DataTable();
                    sqlDataAdapter = new SqlDataAdapter("select ma_nxb,tennxb from nha_xuat_ban;", Connection.sqlConnection);
                    sqlDataAdapter.Fill(table_nxb);
                    cbomanxb.DataSource = table_nxb;
                    cbomanxb.ValueMember = "ma_nxb";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi: " + ex.Message);
                }
            }
            
        }

        private void xtraTabPagedsdgia_Leave(object sender, EventArgs e)
        {
            xtraTabPagedsdgia.PageVisible = false;
        }

        private void xtraTabPagedsdgia_Leave_1(object sender, EventArgs e)
        {
            xtraTabPagedsdgia.PageVisible = false;
            xtraTabControl2.SelectedTabPage = xtraTabPagesachmoi;
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            xtraTabPagedsdgia.PageVisible = false;
            
        }

        private void rgbiSkins_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            this.skinsRibbonPageGroup.Visible = false;
        }

        private void rgbiSkins_GalleryItemClick(object sender, GalleryItemClickEventArgs e)
        {
            
        }

        private void barsuadocgia_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmsuadocgia Frmsuadocgia = new frmsuadocgia();
            Frmsuadocgia.ShowDialog();
        }

        private void btnsua_Click_1(object sender, EventArgs e)
        {
            int dem = 0;
            try
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        dem++;
                    }
                }
                if (dem == 0)
                    MessageBox.Show("Bạn chưa chọn đọc giả để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (dem == 1)
                {
                    frmsuadg Frmsuadocgia = new frmsuadg();
                    Frmsuadocgia.ShowDialog();
                }
                else
                    MessageBox.Show("Bạn chỉ được chọn lần lượt từng đọc giả để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btndanhsach_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        

        private void barbtntacgia_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagetacgia.PageVisible = true;
            xtraTabControl2.SelectedTabPage = xtraTabPagetacgia;
        }

        private void btntkiem_Click(object sender, EventArgs e)
        {
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from tac_gia where ma_tgia='"+cbotentg.Text+"';",Connection.sqlConnection);
            DataTable dataTable = new DataTable();
            sqlDataAdapter.Fill(dataTable);
            this.dataGridView2.DataSource = dataTable;
            sqlDataAdapter.Dispose();
        }

        private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            dataGridView1.ClearSelection();
        }

        private void btnexit_Click(object sender, EventArgs e)
        {
            xtraTabPagetacgia.PageVisible = false;
        }

        public void btnds_Click(object sender, EventArgs e)
        {
            dataTabletacgia.Clear();
            try
            {

                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from tac_gia;", Connection.sqlConnection);
                sqlDataAdapter.Fill(dataTabletacgia);
                this.dataGridView2.DataSource = dataTabletacgia;
                this.dataGridView2.ClearSelection();

                //load du lieu len cbotacgia
                DataTable table_tgia = new DataTable();
                sqlDataAdapter = new SqlDataAdapter("select ma_tgia,ten_tgia,hocvi from tac_gia;", Connection.sqlConnection);
                sqlDataAdapter.Fill(table_tgia);
                cbotentg.DataSource = table_tgia;
                cbotentg.ValueMember = "ma_tgia";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void btnxoatg_Click(object sender, EventArgs e)
        {
            int dem = 0;
            int ktra = 0;
            try
            {
                foreach (DataGridViewRow row in dataGridView2.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        ktra++;
                    }
                }
                if (ktra == 0)
                    MessageBox.Show("Bạn chưa chọn tác giả để xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (MessageBox.Show("Bạn thật sự muốn xóa!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in dataGridView2.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells[0].Value))
                        {
                            string idToDelete = row.Cells[1].Value.ToString();
                            SqlCommand lenh = new SqlCommand("delete from tac_gia where ma_tgia='" + idToDelete + "'", Connection.sqlConnection);
                            int n = lenh.ExecuteNonQuery();
                            dem++;
                        }
                    }
                }
                btnds_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void dataGridView2_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            dataGridView2.ClearSelection();
        }

        private void btnsuatg_Click(object sender, EventArgs e)
        {
            int dem = 0;
            try
            {
                foreach (DataGridViewRow row in dataGridView2.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        dem++;
                    }
                }
                if (dem == 0)
                    MessageBox.Show("Bạn chưa chọn tác giả để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (dem == 1)
                {
                    frmsuatacgia Frmsuatacgia = new frmsuatacgia();
                    Frmsuatacgia.ShowDialog();
                }
                else
                    MessageBox.Show("Bạn chỉ được chọn lần lượt từng tác giả để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnds_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void barbtnsaoluu_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmsaoluu Frmsaoluu = new frmsaoluu();
            Frmsaoluu.ShowDialog();
        }

        private void barbtnphuchoi_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmphuchoi phuchoi = new frmphuchoi();
            phuchoi.ShowDialog();
            
            
        }

        private void barsaoluu_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmsaoluu Frmsaoluu = new frmsaoluu();
            Frmsaoluu.ShowDialog();
        }

        private void barphuchoi_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmphuchoi Frmphuchoi = new frmphuchoi();
            Frmphuchoi.ShowDialog();
        }

        private void barbtnmuon_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmmuonsach Frmmuonsach = new frmmuonsach();
            Frmmuonsach.ShowDialog();
        }

        private void chkmathe1_CheckedChanged(object sender, EventArgs e)
        {
            if (chkmathe1.Checked)
            {
                cbomathe1.Enabled = true;
                DataTable bangmathe = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select mathe from the_doc_gia", Connection.sqlConnection);
                sqlDataAdapter.Fill(bangmathe);
                cbomathe1.DataSource = bangmathe;
                cbomathe1.ValueMember = "mathe";
            }
            else
                cbomathe1.Enabled = false;
        }

        private void chkISBN_CheckedChanged(object sender, EventArgs e)
        {
            if (chkISBN.Checked)
            {
                cboISBN.Enabled = true;
                chksttcuon.Enabled = true;
                DataTable bangISBN = new DataTable();
                SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select isbn,trangthai from dau_sach", Connection.sqlConnection);
                sqlDataAdapter1.Fill(bangISBN);
                cboISBN.DataSource = bangISBN;
                cboISBN.ValueMember = "ISBN";
            }
            else
            {
                cboISBN.Enabled = false;
                chksttcuon.Enabled = false;
            }
        }

        private void chksttcuon_CheckedChanged(object sender, EventArgs e)
        {
            if (chksttcuon.Checked)
                cbosttcuon.Enabled = true;
            else
                cbosttcuon.Enabled = false;
        }

        private void cboISBN_ValueChanged(object sender, EventArgs e)
        {
            DataTable bangsttcuon = new DataTable();
            SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter("select stt_cuon from cuon_sach where isbn='" + cboISBN.Text + "'", Connection.sqlConnection);
            sqlDataAdapter2.Fill(bangsttcuon);
            cbosttcuon.DataSource = bangsttcuon;
            cbosttcuon.ValueMember = "stt_cuon";
        }

        private void barsachdangmuon_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagesachdangmuon.PageVisible = true;
            xtraTabControl2.SelectedTabPage = xtraTabPagesachdangmuon;
        }

        private void btnexitthoat_Click(object sender, EventArgs e)
        {
            xtraTabPagesachdangmuon.PageVisible = false;
        }

        private void chktendg_CheckedChanged(object sender, EventArgs e)
        {
            if (chktendg.Checked)
            {
                cbotendg.Enabled = true;
                DataTable bangtendg = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select hten_dg from the_doc_gia", Connection.sqlConnection);
                sqlDataAdapter.Fill(bangtendg);
                cbotendg.DataSource = bangtendg;
                cbotendg.ValueMember = "hten_dg";
            }
            else
                cbotendg.Enabled = false;
        }

        private void button12_Click(object sender, EventArgs e)
        {
            try
            {
                string dieukien = "";
                if (chkmathe1.Checked)
                    dieukien = " and b.mathe='" + cbomathe1.Text + "'";
                if (chktendg.Checked)
                    dieukien += " and hten_dg=N'" + cbotendg.Text + "'";
                if (chkISBN.Checked)              
                    dieukien += " and d.ISBN=N'" + cboISBN.Text + "'";
                if (chksttcuon.Checked==true && chksttcuon.Enabled==true)
                    dieukien += " and d.ISBN=N'" + cboISBN.Text + "' and stt_cuon="+Convert.ToInt32(cbosttcuon.Text);
                DataTable dataTable = new DataTable();
                SqlDataAdapter sqlDataAdapter;
                if (dieukien != "")
                    sqlDataAdapter = new SqlDataAdapter("select b.stt_phieu,b.mathe,hten_dg,d.isbn,stt_cuon,tuasach,lan_gia_han,ngay_het_han,ghi_chu from the_doc_gia a,phieu_muon b,gom_cuon c,dau_sach d where a.mathe=b.mathe and b.stt_phieu=c.stt_phieu and c.isbn=d.isbn and ngay_gio_tra is null" + dieukien, Connection.sqlConnection);
                else
                    sqlDataAdapter = new SqlDataAdapter("select b.stt_phieu,b.mathe,hten_dg,d.isbn,stt_cuon,tuasach,lan_gia_han,ngay_het_han,ghi_chu from the_doc_gia a,phieu_muon b,gom_cuon c,dau_sach d where a.mathe=b.mathe and b.stt_phieu=c.stt_phieu and c.isbn=d.isbn and b.mathe=''", Connection.sqlConnection);
                sqlDataAdapter.Fill(dataTable);
                sqlDataAdapter.Dispose();
                this.dataGridView6.DataSource = dataTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        internal void btndsach_Click(object sender, EventArgs e)
        {
            chkmathe1.CheckState =CheckState.Unchecked;
            chktendg.CheckState = CheckState.Unchecked;
            chkISBN.CheckState = CheckState.Unchecked;
            chksttcuon.CheckState = CheckState.Unchecked;
            try
            {
                dataTablesachdangmuon.Clear();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select b.stt_phieu,b.mathe,hten_dg,d.isbn,stt_cuon,tuasach,lan_gia_han,ngay_het_han,ghi_chu from the_doc_gia a,phieu_muon b,gom_cuon c,dau_sach d where a.mathe=b.mathe and b.stt_phieu=c.stt_phieu and c.isbn=d.isbn and ngay_gio_tra is null order by b.stt_phieu asc", Connection.sqlConnection);
                sqlDataAdapter.Fill(dataTablesachdangmuon);
                this.dataGridView6.DataSource = dataTablesachdangmuon;
                this.dataGridView6.ClearSelection();
                sqlDataAdapter.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void btnchomuon_Click(object sender, EventArgs e)
        {
            frmmuonsach Frmmuonsach = new frmmuonsach();
            Frmmuonsach.ShowDialog();
        }

        private void barmuon_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmmuonsach Frmmuonsach = new frmmuonsach();
            Frmmuonsach.ShowDialog();
        }

        private void barbtntra_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmtrasach Frmtrasach = new frmtrasach();
            Frmtrasach.ShowDialog();
        }

        private void btntrasach_Click(object sender, EventArgs e)
        {
            int dem = 0;
            int max = 0;
            string mathe = null;
            try
            {
                int test = 0;
                foreach (DataGridViewRow row in dataGridView6.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        test = Convert.ToInt32(row.Cells[1].Value);
                        break;
                    }
                }
                foreach (DataGridViewRow row in dataGridView6.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        if (Convert.ToInt32(row.Cells[1].Value) != test)
                        {
                            MessageBox.Show("Bạn chỉ được ghi nhận trả sách cho từng đọc giả!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            btndsach_Click(sender,e);
                            return;
                        }
                    }
                }
                foreach (DataGridViewRow row in dataGridView6.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        int stt_phieu = Convert.ToInt32(row.Cells[1].Value);
                        string ISBN = row.Cells[4].Value.ToString();
                        int stt_cuon = Convert.ToInt32(row.Cells[5].Value);
                        mathe = row.Cells[2].Value.ToString();
                        SqlCommand lenh = new SqlCommand("update gom_cuon set ngay_gio_tra='" + DateTime.Now + "' where stt_phieu=" + stt_phieu + " and ISBN=N'" + ISBN + "' and stt_cuon=" + stt_cuon, Connection.sqlConnection);
                        int n = lenh.ExecuteNonQuery();

                        lenh = new SqlCommand("select datediff(day,ngay_het_han,ngay_gio_tra) from gom_cuon where ngay_gio_tra>ngay_het_han and ghi_chu is null and " + "stt_phieu=" + stt_phieu + " and ISBN=N'" + ISBN + "' and stt_cuon=" + stt_cuon, Connection.sqlConnection);
                        n = Convert.ToInt32(lenh.ExecuteScalar());

                        lenh = new SqlCommand("update gom_cuon set ghi_chu=N'trả trễ hạn " + n + " ngày' where ngay_het_han<ngay_gio_tra and ghi_chu is null and " + "stt_phieu=" + stt_phieu + " and ISBN=N'" + ISBN + "' and stt_cuon=" + stt_cuon, Connection.sqlConnection);
                        lenh.ExecuteNonQuery();

                        if (n > max) max = n;
                        dem++;
                    }
                }
                if (dem > 0 && max == 0)
                {
                    MessageBox.Show("Đã ghi nhận trả!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (dem > 0 && max > 0)
                {
                    if (MessageBox.Show("Đọc giả trả trễ hạn " + max + " ngày!\n Lập phiếu phạt cho đọc giả?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        frmphatdocgia Frmphatdocgia = new frmphatdocgia();
                        Frmphatdocgia.cbomathe.Text = mathe;
                        Frmphatdocgia.cadngaylap.Text = DateTime.Today.ToString();
                        Frmphatdocgia.txtsotien.Text = Convert.ToString(max * 1000);
                        Frmphatdocgia.txtlydo.Text = "trả trễ hạn " + max + " ngày";
                        Frmphatdocgia.btnluu_Click(sender, e);
                    }

                }
                else
                    MessageBox.Show("Bạn chưa chọn sách để trả!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btndsach_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void bartra_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmtrasach Frmtrasach = new frmtrasach();
            Frmtrasach.ShowDialog();
        }

        string sachhetlangiahan = null;
        string sachkoduocgiahan = null;
        private void btngiahan_Click(object sender, EventArgs e)
        {
            int dem = 0;
            string tuasach = null;
            try
            {
                int test=0;
                foreach (DataGridViewRow row in dataGridView6.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        test = Convert.ToInt32(row.Cells[1].Value);
                        break;
                    }
                }
                foreach (DataGridViewRow row in dataGridView6.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        if (Convert.ToInt32(row.Cells[1].Value) != test)
                        {
                            MessageBox.Show("Bạn chỉ được gia hạn cho từng đọc giả!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            btndsach_Click(sender,e);
                            return;
                        }
                    }
                }
                foreach (DataGridViewRow row in dataGridView6.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value) && (Convert.ToDateTime(row.Cells[8].Value) < Convert.ToDateTime(DateTime.Today.ToShortDateString())))
                    {
                        row.Cells[0].Value = false;
                        sachkoduocgiahan += "- "+Convert.ToString(row.Cells[6].Value) + "\n";
                        dem++;
                    }
                }
                foreach (DataGridViewRow row in dataGridView6.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value) && (Convert.ToDateTime(row.Cells[8].Value) >= Convert.ToDateTime(DateTime.Today.ToShortDateString())))
                    {
                        int stt_phieu = Convert.ToInt32(row.Cells[1].Value);
                        string ISBN = row.Cells[4].Value.ToString();
                        int stt_cuon = Convert.ToInt32(row.Cells[5].Value);
                        tuasach = Convert.ToString(row.Cells[6].Value);
                        row.Cells[0].Value = false;
                        SqlCommand lenh = new SqlCommand("update gom_cuon set lan_gia_han=lan_gia_han+1,ngay_het_han=dateadd(day,7,ngay_het_han) where stt_phieu=" + stt_phieu + " and ISBN=N'" + ISBN + "' and stt_cuon=" + stt_cuon, Connection.sqlConnection);
                        int n = lenh.ExecuteNonQuery();
                        dem++;
                    }
                }
                if (sachkoduocgiahan == null && sachhetlangiahan == null && dem > 0)
                    MessageBox.Show("Gia hạn thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                else if (sachkoduocgiahan != null && sachhetlangiahan != null && dem > 0)
                {
                    MessageBox.Show("Đã gia hạn ngoại trừ các quyển: \n" + sachkoduocgiahan + " Lý do: đã trễ hạn trả!\n" + sachhetlangiahan + "Lý do: đã hết số lần gia hạn!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    sachkoduocgiahan = null;
                }
                else if (sachkoduocgiahan != null && sachhetlangiahan != null && dem == 0)
                {
                    MessageBox.Show("Đã gia hạn ngoại trừ các quyển: \n" + sachkoduocgiahan + " Lý do: đã trễ hạn trả!\n" + sachhetlangiahan + "Lý do: đã hết số lần gia hạn!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    sachkoduocgiahan = null;
                }
                else if (sachkoduocgiahan != null && sachhetlangiahan == null && dem == 0)
                {
                    MessageBox.Show("Gia hạn thất bại: \n" + sachkoduocgiahan + "Lý do: đã trễ hạn trả!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    sachkoduocgiahan = null;
                }
                else if (sachkoduocgiahan != null && sachhetlangiahan == null && dem > 0)
                {
                    MessageBox.Show("Đã gia hạn ngoại trừ các quyển: \n" + sachkoduocgiahan + " Lý do: đã trễ hạn trả!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    sachkoduocgiahan = null;
                }
                else if (sachkoduocgiahan == null && sachhetlangiahan != null && dem > 0)
                {
                    MessageBox.Show("Đã gia hạn ngoại trừ các quyển: \n" + sachhetlangiahan + "Lý do: đã hết số lần gia hạn!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    sachkoduocgiahan = null;
                }
                else if (sachkoduocgiahan == null && sachhetlangiahan != null && dem == 0)
                {
                    MessageBox.Show("Gia hạn thất bại: \n" + sachhetlangiahan + "Lý do: đã hết số lần gia hạn!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    sachkoduocgiahan = null;
                }
                else
                    MessageBox.Show("Bạn chưa chọn sách để gia hạn!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);

                btndsach_Click(sender, e);
            }
            catch (Exception ex)
            {
                sachhetlangiahan += "- " + tuasach + "\n";
                btngiahan_Click(sender, e);
                sachhetlangiahan = null;
            }
        }

        private void barbtnphat_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmphatdocgia Frmphatdocgia = new frmphatdocgia();
            Frmphatdocgia.ShowDialog();
        }

        private void barphat_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmphatdocgia Frmphatdocgia = new frmphatdocgia();
            Frmphatdocgia.ShowDialog();
        }

        private void btnedit_Click(object sender, EventArgs e)
        {
            int dem = 0;
            try
            {
                foreach (DataGridViewRow row in dataGridView6.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        dem++;
                    }
                }
                if (dem == 0)
                    MessageBox.Show("Bạn chưa chọn thông tin mượn để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (dem == 1)
                {
                    frmsuamuonsach Frmsuamuonsach = new frmsuamuonsach();
                    foreach (DataGridViewRow row in dataGridView6.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells[0].Value))
                        {
                            Frmsuamuonsach.txtstt_phieu.Text = Convert.ToString(row.Cells[1].Value);
                            Frmsuamuonsach.cbomathe.Text = Convert.ToString(row.Cells[2].Value);
                            Frmsuamuonsach.cboISBN.Text = Convert.ToString(row.Cells[4].Value);
                            Frmsuamuonsach.cbosttcuon.Text = Convert.ToString(row.Cells[5].Value);
                            Frmsuamuonsach.cadngayhethan.Text=Convert.ToString(row.Cells[8].Value);

                            SqlCommand lenh = new SqlCommand("select ngay_gio_muon from phieu_muon where stt_phieu="+Convert.ToInt32(row.Cells[1].Value),Connection.sqlConnection);
                            string giomuon = Convert.ToDateTime(lenh.ExecuteScalar()).ToLongTimeString();
                            string ngaymuon = Convert.ToDateTime(lenh.ExecuteScalar()).ToLongDateString();
                            Frmsuamuonsach.cadngaymuon.Text = ngaymuon;
                            Frmsuamuonsach.txtgiomuon.Text = giomuon;
                            //
                            lenh = new SqlCommand("select path_anh from dau_sach where isbn='" + Convert.ToString(row.Cells[4].Value) + "'", Connection.sqlConnection);
                            Image hinh = Image.FromFile(Convert.ToString(lenh.ExecuteScalar()));
                            Frmsuamuonsach.pictureBox1.Image = hinh;
                        }
                    }
                    Frmsuamuonsach.ShowDialog();
                }
                else
                    MessageBox.Show("Bạn chỉ được chọn lần lượt từng đọc giả để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btndanhsach_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        

        private void dataGridView6_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            dataGridView6.ClearSelection();
        }

        private void chktuasach_CheckedChanged(object sender, EventArgs e)
        {
            if (chktuasach.Checked)
            {
                //load du lieu len cbotuasach
                cbotuasach.Enabled = true;
                DataTable bangtuasach = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select tuasach from dau_sach",Connection.sqlConnection);
                sqlDataAdapter.Fill(bangtuasach);
                cbotuasach.DataSource = bangtuasach;
                cbotuasach.DisplayMember = "tuasach";
                cbotuasach.ValueMember = "tuasach";
            }
            else
                cbotuasach.Enabled = false;
        }

        private void chktacgia_CheckedChanged(object sender, EventArgs e)
        {
            if (chktacgia.Checked)
            {
                cbotentacgia.Enabled = true;
                //load du lieu len cbotentacgia
                DataTable bangtentacgia = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select ten_tgia from tac_gia", Connection.sqlConnection);
                sqlDataAdapter.Fill(bangtentacgia);
                cbotentacgia.DataSource = bangtentacgia;
                cbotentacgia.DisplayMember = "ten_tgia";
                cbotentacgia.ValueMember = "ten_tgia";
            }
            else
                cbotentacgia.Enabled = false;
        }

        private void chknxb_CheckedChanged(object sender, EventArgs e)
        {
            if (chknxb.Checked)
            {
                cbonxb.Enabled = true;
                //load du lieu len cbonxb
                DataTable bangnxb = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select tennxb from nha_xuat_ban", Connection.sqlConnection);
                sqlDataAdapter.Fill(bangnxb);
                cbonxb.DataSource = bangnxb;
                cbonxb.DisplayMember = "tennxb";
                cbonxb.ValueMember = "tennxb";
            }
            else
                cbonxb.Enabled = false;
        }

       

        private void chktheloai_CheckedChanged(object sender, EventArgs e)
        {
            if (chktheloai.Checked)
            {
                cbotheloai.Enabled = true;
                //load du lieu len cbonxb
                DataTable bangtheloai = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select ten_tloai from the_loai", Connection.sqlConnection);
                sqlDataAdapter.Fill(bangtheloai);
                cbotheloai.DataSource = bangtheloai;
                cbotheloai.DisplayMember = "ten_tloai";
                cbotheloai.ValueMember = "ten_tloai";
            }
            else
                cbotheloai.Enabled = false;
        }

        private void chkngonngu_CheckedChanged(object sender, EventArgs e)
        {
            if (chkngonngu.Checked)
            {
                cbongonngu.Enabled = true;
                //load du lieu len cbonxb
                DataTable bangngonngu = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select ten_nn from ngon_ngu", Connection.sqlConnection);
                sqlDataAdapter.Fill(bangngonngu);
                cbongonngu.DataSource = bangngonngu;
                cbongonngu.DisplayMember = "ten_nn";
                cbongonngu.ValueMember = "ten_nn";
            }
            else
                cbongonngu.Enabled = false;
        }

        private void chktthaimuon_CheckedChanged(object sender, EventArgs e)
        {
            if (chktthaimuon.Checked)
            {
                cbotthaimuon.Enabled = true;
                //load du lieu len cbonxb
                DataTable bangtthaimuon = new DataTable();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select distinct tinhtrang from cuon_sach", Connection.sqlConnection);
                sqlDataAdapter.Fill(bangtthaimuon);
                cbotthaimuon.DataSource = bangtthaimuon;
                cbotthaimuon.DisplayMember = "tinhtrang";
                cbotthaimuon.ValueMember = "tinhtrang";
            }
            else
                cbotthaimuon.Enabled = false;
        }

        private void chktukhoa_CheckedChanged(object sender, EventArgs e)
        {
            if (chktukhoa.Checked)
            {
                chktuasach.CheckState = CheckState.Unchecked;
                chktuasach.Enabled = false;
                chktacgia.CheckState = CheckState.Unchecked;
                chktacgia.Enabled = false;
                chknxb.CheckState = CheckState.Unchecked;
                chknxb.Enabled = false;
                chknamxb.CheckState = CheckState.Unchecked;
                chknamxb.Enabled = false;
                chktheloai.CheckState = CheckState.Unchecked;
                chktheloai.Enabled = false;
                chkngonngu.CheckState = CheckState.Unchecked;
                chkngonngu.Enabled = false;
                chktthaimuon.CheckState = CheckState.Unchecked;
                chktthaimuon.Enabled = false;
                txttukhoa.Enabled = true;
            }
            else
            {
                txttukhoa.Enabled = false;
                chktuasach.Enabled = true;
                chktacgia.Enabled = true;
                chknxb.Enabled = true;
                chknamxb.Enabled = true;
                chktheloai.Enabled = true;
                chkngonngu.Enabled = true;
                chktthaimuon.Enabled = true;
            }
        }

        private void chknamxb_CheckedChanged(object sender, EventArgs e)
        {
            if (chknamxb.Checked)
                txtnamxb.Enabled = true;
            else
                txtnamxb.Enabled = false;
        }

        private void btntim_Click(object sender, EventArgs e)
        {
            
            try
            {
                string dieukien = "";
                if (chktuasach.Checked)
                {
                    dieukien = " and tuasach=N'" + cbotuasach.Text + "'";
                }
                if (chktacgia.Checked)
                {
                    dieukien += " and ten_tgia=N'" + cbotentacgia.Text + "'";
                }
                if (chknxb.Checked)
                {
                    dieukien += " and tennxb=N'" + cbonxb.Text + "'";
                }
                if (chknamxb.Checked)
                {
                    dieukien += " and namxb=" + Convert.ToInt32(txtnamxb.Text);
                }
                if (chktheloai.Checked)
                {
                    dieukien += " and ten_tloai=N'" + cbotheloai.Text + "'";
                }
                if (chkngonngu.Checked)
                {
                    dieukien += " and ten_nn=N'" + cbongonngu.Text + "'";
                }
                if (chktthaimuon.Checked)
                {
                    dieukien += " and tinhtrang=N'" + cbotthaimuon.Text + "'";
                }
                if (chktukhoa.Checked)
                {
                    dieukien += " and tukhoa=N'" + txttukhoa.Text + "'";
                }
                DataTable dataTable = new DataTable();
                SqlDataAdapter sqlDataAdapter;
                if (dieukien != "")
                {
                    sqlDataAdapter = new SqlDataAdapter("select distinct a.isbn,b.stt_cuon,tuasach,tennxb,namxb,ten_nn,ten_tloai,sotrang,tinhtrang into #temp from dau_sach a join cuon_sach b on a.isbn=b.isbn join bien_soan c on a.isbn=c.isbn join tac_gia d on c.ma_tgia=d.ma_tgia join nha_xuat_ban e on a.ma_nxb=e.ma_nxb join ngon_ngu f on a.ma_nn=f.ma_nn join the_loai g on a.ma_tloai=g.ma_tloai join tu_khoa_dai_dien h on a.isbn=h.isbn join tu_khoa i on h.ma_tkhoa=i.ma_tkhoa " + dieukien + " select distinct isbn,stt_cuon,hten_dg,ngay_het_han into #temp1 from gom_cuon a join phieu_muon b on a.stt_phieu=b.stt_phieu join the_doc_gia c on b.mathe=c.mathe where ngay_gio_tra is null " + " select distinct #temp.isbn,#temp.stt_cuon,tuasach,tennxb,namxb,ten_nn,ten_tloai,sotrang,tinhtrang,hten_dg,ngay_het_han from #temp left join #temp1 on #temp.isbn=#temp1.isbn and #temp.stt_cuon=#temp1.stt_cuon drop table #temp,#temp1", Connection.sqlConnection);
                    sqlDataAdapter.Fill(dataTable);
                    sqlDataAdapter.Dispose();
                }
                else
                    MessageBox.Show("Bạn chưa nhập thông tin tra cứu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.dataGridView4.DataSource = dataTable;
                xtraTabPagekqtimkiem.PageVisible = true;
                xtraTabControl2.SelectedTabPage = xtraTabPagekqtimkiem;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void bardsmuontheoquyen_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "BÁO CÁO LƯỢT MƯỢN \nTHEO TỪNG QUYỂN";
            grbtheongay.Enabled = true;
            grbtheonam.Enabled = false;
        }

        private void btnthoatexit_Click(object sender, EventArgs e)
        {
            xtraTabPagebaocao.PageVisible = false;
        }

        private void barmuontungnam_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "BÁO CÁO LƯỢT MƯỢN \nTHEO TỪNG NĂM";
            grbtheongay.Enabled = false;
            grbtheonam.Enabled = true;
        }

        private void bardsbiphat_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "DANH SÁCH ĐỌC GIẢ \nBỊ PHẠT";
            grbtheongay.Enabled = true;
            grbtheonam.Enabled = false;
        }

        private void bardsquahan_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "DANH SÁCH ĐỌC GIẢ \n MƯỢN QUÁ HẠN";
            grbtheongay.Enabled = true;
            grbtheonam.Enabled = false;
        }

        private void barsachkomuon_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "BÁO CÁO SÁCH \nKHÔNG AI MƯỢN";
        }

        private void barsachmuonnhieu_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "BÁO CÁO SÁCH \nĐƯỢC MƯỢN NHIỀU";
        }

        private void btnin_Click(object sender, EventArgs e)
        {
            if ((Convert.ToDateTime(caddenngay.Text) < Convert.ToDateTime(cadtungay.Text)) && grbtheongay.Enabled==true)
            {
                MessageBox.Show("Bạn phải nhập khoảng thời gian lơn hơn 0!","Thông báo",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            if (txttunam.Text != "" && txtdennam.Text != "")
            {
                if ((Convert.ToInt32(txttunam.Text) > Convert.ToInt32(txtdennam.Text)) && grbtheonam.Enabled == true)
                {
                    MessageBox.Show("Bạn phải nhập khoảng thời gian lơn hơn 0!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            frmbao_cao frmluot_muon = new frmbao_cao();
            frmluot_muon.ShowDialog();
        }

        private void btndong_Click(object sender, EventArgs e)
        {
            xtraTabPagekqtimkiem.PageVisible = false;
        }

        private void btnthemtg_Click(object sender, EventArgs e)
        {
            frmthemtacgia frmthemtg = new frmthemtacgia();
            frmthemtg.ShowDialog();
        }

        private void barbtnloaidg_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagenxb.PageVisible = true;
            xtraTabControl2.SelectedTabPage = xtraTabPagenxb;
        }

        private void btnsearch_Click(object sender, EventArgs e)
        {
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from nha_xuat_ban where ma_nxb='" + cbomanxb.Text + "';", Connection.sqlConnection);
            DataTable dataTable = new DataTable();
            sqlDataAdapter.Fill(dataTable);
            this.dataGridView5.DataSource = dataTable;
            sqlDataAdapter.Dispose();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            xtraTabPagenxb.PageVisible = false;
        }

        internal void button14_Click(object sender, EventArgs e)
        {
            dataTablenxb.Clear();
            try
            {
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from nha_xuat_ban;", Connection.sqlConnection);
                sqlDataAdapter.Fill(dataTablenxb);
                this.dataGridView5.DataSource = dataTablenxb;
                this.dataGridView5.ClearSelection();

                //load du lieu len cbomanxb
                DataTable table_nxb = new DataTable();
                sqlDataAdapter = new SqlDataAdapter("select ma_nxb,tennxb from nha_xuat_ban;", Connection.sqlConnection);
                sqlDataAdapter.Fill(table_nxb);
                cbomanxb.DataSource = table_nxb;
                cbomanxb.ValueMember = "ma_nxb";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void button15_Click(object sender, EventArgs e)
        {
            int dem = 0;
            int ktra = 0;
            try
            {
                foreach (DataGridViewRow row in dataGridView5.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        ktra++;
                    }
                }
                if (ktra == 0)
                    MessageBox.Show("Bạn chưa chọn nhà xuất bản để xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (MessageBox.Show("Bạn thật sự muốn xóa!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in dataGridView5.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells[0].Value))
                        {
                            string idToDelete = row.Cells[1].Value.ToString();
                            SqlCommand lenh = new SqlCommand("delete from nha_xuat_ban where ma_nxb='" + idToDelete + "'", Connection.sqlConnection);
                            int n = lenh.ExecuteNonQuery();
                            dem++;
                        }
                    }
                }
                button14_Click(sender,e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            frmthemnxb Frmthemnxb = new frmthemnxb();
            Frmthemnxb.ShowDialog();
        }

        private void dataGridView5_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            dataGridView5.ClearSelection();
        }

        private void btnallter_Click(object sender, EventArgs e)
        {
            int dem = 0;
            try
            {
                foreach (DataGridViewRow row in dataGridView5.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[0].Value))
                    {
                        dem++;
                    }
                }
                if (dem == 0)
                    MessageBox.Show("Bạn chưa chọn nhà xuất bản để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (dem == 1)
                {
                    frmsuanxb Frmsuanxb = new frmsuanxb();
                    Frmsuanxb.ShowDialog();
                }
                else
                    MessageBox.Show("Bạn chỉ được chọn lần lượt từng nhà xuất bản để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                button14_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }

        private void barquahan_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "DANH SÁCH ĐỌC GIẢ \n MƯỢN QUÁ HẠN";
            grbtheongay.Enabled = true;
            grbtheonam.Enabled = false;
        }

        private void bardsphat_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "DANH SÁCH ĐỌC GIẢ \nBỊ PHẠT";
            grbtheongay.Enabled = true;
            grbtheonam.Enabled = false;
        }

        private void barlmquyen_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "BÁO CÁO LƯỢT MƯỢN \nTHEO TỪNG QUYỂN";
            grbtheongay.Enabled = true;
            grbtheonam.Enabled = false;
        }

        private void barlmtl_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "BÁO CÁO LƯỢT MƯỢN \nTHEO TỪNG THỂ LOẠI";
            grbtheongay.Enabled = true;
            grbtheonam.Enabled = false;
        }

        private void barlmnam_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabPagebaocao.PageVisible = true;
            xtraTabControl1.SelectedTabPage = xtraTabPagebaocao;
            lblbaocao.Text = "BÁO CÁO LƯỢT MƯỢN \nTHEO TỪNG NĂM";
            grbtheongay.Enabled = false;
            grbtheonam.Enabled = true;
        }

        private void barButtonItem35_ItemClick(object sender, ItemClickEventArgs e)
        {
            System.Diagnostics.Process.Start("..\\..\\Help.chm");
        }

        private void barButtonItem34_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmchuongtrinhinfo info_program = new frmchuongtrinhinfo();
            info_program.Show();
        }

        private void barButtonItem46_ItemClick(object sender, ItemClickEventArgs e)
        {
            System.Diagnostics.Process.Start("..\\..\\Help.chm");
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void xtraTabControl2_Click(object sender, EventArgs e)
        {

        }

        

        
        

        
        

        

        
             
    }
}